//
//  HuanKuanAlertview.m
//  wangzhe
//
//  Created by 李 佳伟 on 2018/1/2.
//  Copyright © 2018年 李 佳伟. All rights reserved.
//

#import "HuanKuanAlertview.h"
#import "JTCSM.h"

static CGFloat imagesize = 100;
static CGFloat labelHeight = 60;
static CGFloat space = 50;
static CGFloat top = 10;
static CGFloat btnheight  = 30;
static CGFloat btnspace = 40;
static HuanKuanAlertview *single = nil;

@implementation HuanKuanAlertview

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

+(HuanKuanAlertview *)shareSingle{
    @synchronized(self){
        if(single == nil){
            
            single =[ [HuanKuanAlertview alloc] init];
        }
        
    }
    return single;
}

- (id)init
{
    self= [super init];
    if (self) {
        self.backgroundColor = RGBACOLOR(0, 0, 0, 0.3);
         self.frame = CGRectMake(0, 0, KSCREENWidth, KSCREENHeight);
        UIView *backview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KSCREENWidth-2*space, imagesize/2+labelHeight+top*3+btnheight)];
        backview.backgroundColor = [UIColor whiteColor];
        [df layerWithView:backview radius:5 width:0 color:nil];
        backview.center = self.center;
        [self addSubview:backview];
        
        
        imageview = [[UIImageView alloc]initWithFrame:CGRectMake((KSCREENWidth-imagesize)/2, backview.frame.origin.y-imagesize/2, imagesize, imagesize)];
        [self addSubview:imageview];
        
        contentLabel = [UILabel initWithFrame:CGRectMake(10, imagesize/2, backview.frame.size.width-20, labelHeight) text:@"" font:14 textAlignment:NSTextAlignmentCenter texcolor:RGBACOLOR(192, 192, 192, 1) backgroundColor:nil];
        contentLabel.numberOfLines = 3;
        [backview addSubview:contentLabel];
        
        CGFloat backviewWidth = backview.frame.size.width;
        UIButton *LoginBtn =[[UIButton alloc] initWithFrame:CGRectMake(btnspace, KVIEW_Y(contentLabel)+top , (backviewWidth-3*btnspace)/2, btnheight)];
        LoginBtn.backgroundColor =RGBACOLOR(227, 68, 40, 1);
        [LoginBtn setTitle:@"确定" forState:UIControlStateNormal];
        [LoginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        //[df layerWithView:LoginBtn radius:4 width:2 color:RGBACOLOR(172,134,171, 1)];
        [LoginBtn addTarget:self action:@selector(gotoMainV) forControlEvents:UIControlEventTouchUpInside];
        [backview addSubview:LoginBtn];
        [df layerWithView:LoginBtn radius:btnheight/2 width:0 color:nil];
        
        UIButton *canclebtn =[[UIButton alloc] initWithFrame:CGRectMake(btnspace +KVIEW_X(LoginBtn), KVIEW_Y(contentLabel)+top , (backviewWidth-3*btnspace)/2, btnheight)];
        canclebtn.backgroundColor =[UIColor whiteColor];
        [canclebtn setTitle:@"取消" forState:UIControlStateNormal];
        [canclebtn setTitleColor:RGBACOLOR(227, 68, 40, 1) forState:UIControlStateNormal];
        //[df layerWithView:LoginBtn radius:4 width:2 color:RGBACOLOR(172,134,171, 1)];
        [canclebtn addTarget:self action:@selector(hiddenmyself) forControlEvents:UIControlEventTouchUpInside];
        [backview addSubview:canclebtn];
        [df layerWithView:canclebtn radius:btnheight/2 width:1 color:RGBACOLOR(227, 68, 40, 1)];
        
    }
    return self;
}

- (void)showWithcontent:(NSString *)content{
    [[JTCSMSingle shareSingle].theWindow addSubview:self];

    
    imageview.image = [UIImage imageNamed:@"huangkuanalert.png"];
    contentLabel.text = content;
   
}

- (void)gotoMainV{
    [self.delegate sureButton];
}

- (void)hiddenmyself{
    [self removeFromSuperview];
}


@end
